const express = require('express')
const session = require('express-session')
const ejs = require('ejs')
const bodyParser = require('body-parser'); 

const app = express()
const port = process.env.PORT || 3000

app.use(express.static('public'))
app.set('views', './views')
app.engine('html', ejs.__express)
app.set('view engine', 'html')

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: true
}))

const signinRouter = require('./routes/signin');
app.use('/signin', signinRouter);

const signupRouter = require('./routes/signup');
app.use('/signup', signupRouter);

const queryRouter = require('./routes/query');
app.use('/query', queryRouter);

const orderRouter = require('./routes/order');
app.use('/order', orderRouter);

const resultRouter = require('./routes/result');
app.use('/result', resultRouter);

app.get('/', (req, res) => {
    if(req.session.logged){
        res.render('index', {
            logged: req.session.logged,
            name: req.session.name,
            studentID: req.session.studentID,
            gender: req.session.gender
        })
    }
    else{
        res.render('index', {logged: false})

    }
    
})


app.listen(port, () => {
  console.log(`Listening on port ${port}...`)
})
